

module static_seg_led (
    input sys_clk,
    input sys_rst,
    input seg_add_flag,
    
    output reg  [7:0] seg_led,           ///数码管段位
    output reg [5:0] seg_led_sel        //数码管选择位
);


//数码管显示的数字

reg [3:0] seg_led_disp_num;

always @(posedge sys_clk or negedge sys_rst) begin
    if (!sys_rst)
        seg_led_sel <= 6'b111111;           //复位全关闭
    else
        seg_led_sel <=  6'b000000;
end

//通过按键控制显示值自增
always @(posedge sys_clk or negedge sys_rst) begin

    if (!sys_rst)
        seg_led_disp_num <= 4'h0;
    else if (seg_add_flag == 1'b1) begin
        if (seg_led_disp_num <= 4'hf) 
            seg_led_disp_num <= seg_led_disp_num + 1'b1;
        else
            seg_led_disp_num <= 4'h0;
    end
    else    
        seg_led_disp_num <= seg_led_disp_num;
end

/*数码管显示数值*/
always @(posedge sys_clk or negedge sys_rst) begin
    if (!sys_rst)
        seg_led <= 8'b0;
    else begin
        case (seg_led_disp_num )
            4'h0 :    seg_led <= 8'b1100_0000;
            4'h1 :    seg_led <= 8'b1111_1001;
            4'h2 :    seg_led <= 8'b1010_0100;
            4'h3 :    seg_led <= 8'b1011_0000;
            4'h4 :    seg_led <= 8'b1001_1001;
            4'h5 :    seg_led <= 8'b1001_0010;
            4'h6 :    seg_led <= 8'b1000_0010;
            4'h7 :    seg_led <= 8'b1111_1000;
            4'h8 :    seg_led <= 8'b1000_0000;
            4'h9 :    seg_led <= 8'b1001_0000;
            4'ha :    seg_led <= 8'b1000_1000;
            4'hb :    seg_led <= 8'b1000_0011;
            4'hc :    seg_led <= 8'b1100_0110;
            4'hd :    seg_led <= 8'b1010_0001;
            4'he :    seg_led <= 8'b1000_0110;
            4'hf :    seg_led <= 8'b1000_1110;
            default : seg_led <= 8'b1100_0000;
        endcase
    end
end

endmodule